<template>
  <div v-if="detail.id">
    <PageTitle title="普通用户退单详情"></PageTitle>
    <div class="form-wrapper">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <!-- <el-form-item label="加盟商名称" prop="class_name">
          <span></span>
        </el-form-item> -->
        <el-form-item label="订单号">
          <span>{{ detail.order_code }}</span>
        </el-form-item>
        <el-form-item label="商品名称">
          <span>{{ detail.title }}</span>
        </el-form-item>
        <el-form-item label="规格名称">
          <span>{{ detail.name }}</span>
        </el-form-item>
        <el-form-item label="数量">
          <span>{{ detail.out_num }}</span>
        </el-form-item>
        <el-form-item label="退单原因">
          <span>{{ detail.out_reason }}</span>
        </el-form-item>
        <el-form-item label="图片">
          <template v-for="(item, index) in detail.imgArr">
            <img class="return-detail-img" :src="item[0].url" @click="handlePictureCardPreview(item[0].url)" :key="index">
          </template>
        </el-form-item>
        <el-form-item label="退货状态">
          <span class="color-success" v-if="detail.out_status == 1">加盟商审核通过</span>
          <span class="color-info" v-if="detail.out_status == 3">等待待审核</span>
          <span class="color-danger" v-if="detail.out_status == 2">审核不通过,原因：{{ detail.reason }}</span>
          <span class="color-theme" v-if="detail.out_status == 4">加盟商已发货</span>
          <span class="color-warning" v-if="detail.out_status == 5">退货已完成</span>
        </el-form-item>
        <el-form-item label="审核状态" prop="status" v-if="detail.out_status == 3">
          <el-select v-model="ruleForm.status" placeholder="审核是否通过">
            <el-option label="通过" value="1"></el-option>
            <el-option label="不通过" value="2"></el-option>
          </el-select>
        </el-form-item>
        <template v-if="detail.out_status == 3 && ruleForm.status == 2 ">
          <el-form-item label="审核原因" prop="reason">
            <el-input v-model="ruleForm.reason"></el-input>
          </el-form-item>
        </template>
        <el-form-item>
          <el-button @click="$router.go(-1)">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
  </div>
</template>

<script>
  import PageTitle from '@/components/pageTitle/PageTitle.vue'
  export default {
    name: 'ReturnDetail',
    components: {
      PageTitle
    },
    activated() {
      this.$goTop()
      this._get()
    },
    deactivated() {
      this.$destroy()
    },
    data() {
      return {
        detail: {},
        ruleForm: {
          status: '',
          reason: ''
        },
        rules: {
          status: [
            { required: true, message: '请选择审核状态', trigger: 'change' }
          ],
          reason: [
            { required: true, message: '请输入审核原因', trigger: 'blur' }
          ]
        },
        dialogImageUrl: '',
        dialogVisible: false
      }
    },
    computed: {
      
    },
    methods: {
      async _get() {
        let { data: { code, data } } = await this.$axios({
          url: this.$api + '/v1/merchant/feeling',
          method: 'GET',
          params: {
            order: this.$route.params.order,
            id: this.$route.params.id
          }
        })
        if (code === 0) {
          this.detail = {
            ...data.items[0],
            imgArr: data.pic
          }
        }
      },
      handlePictureCardPreview(url) {
        this.dialogImageUrl = url
        this.dialogVisible = true
      }
    }
  }
</script>

<style lang="scss">
  .return-detail-img {
    margin-right: 10px;
    width: 100px;
    height: 100px;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.2s linear;
    &:hover {
      box-shadow: 0 2px 3px 0px #ccc;
    }
  }
</style>
